package com.zkingsoft.actions.visitor;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.jdbc.core.ArgumentTypePreparedStatementSetter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.model.web.WebAd;
import com.zkingsoft.model.web.WebArticle;
import com.zkingsoft.model.web.WebArticleType;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.web.WebAdService;
import com.zkingsoft.services.web.WebArticleService;
import com.zkingsoft.services.web.WebArticleTypeService;
import com.zkingsoft.util.WebUtil;

/**
 * 
 * @Description: 不需要登录可以访问的action
 * @author:姜友瑶
 * @date 2016年8月31日
 */
@Controller
public class Home extends BaseController {

	@Resource
	WebAdService webAdService;

	@Resource
	WebArticleService artService;

	@Resource
	WebArticleTypeService artTypeService;

	/**
	 * 
	 * @Description: 首页配置
	 * @author:姜友瑶
	 * @return 返回类型 String
	 * @date 2016年8月28日
	 */
	@RequestMapping(value = "/")
	public String redirect() {

		List<WebAd> lbt = webAdService.findAdByCloName("首页轮播大图");
		List<WebAd> syhdzp = webAdService.findAdByCloName("首页活动照片");
		List<WebAd> cpallb = webAdService.findAdByCloName("产品案例轮播");
		List<WebAd> qyxw = webAdService.findAdByCloName("首页企业新闻");
		List<WebAd> hzhb = webAdService.findAdByCloName("合作伙伴");

		WebAd qyjj = webAdService.findAdByCloNameOne("企业简介");
		WebAd fzlc = webAdService.findAdByCloNameOne("发展历程");
		WebAd syxwdt = webAdService.findAdByCloNameOne("首页企业新闻带图");

		WebUtil.setRequestAttribute("lbt", lbt);
		WebUtil.setRequestAttribute("syhdzp", syhdzp);
		WebUtil.setRequestAttribute("cpallb", cpallb);
		WebUtil.setRequestAttribute("qyxw", qyxw);
		WebUtil.setRequestAttribute("hzhb", hzhb);
		WebUtil.setRequestAttribute("lbt", lbt);
		WebUtil.setRequestAttribute("qyjj", qyjj);
		WebUtil.setRequestAttribute("fzlc", fzlc);
		WebUtil.setRequestAttribute("syxwdt", syxwdt);

		return "/visitor/index";
	}

	@RequestMapping(value = "visitor/productCase")
	public String productCase() {

		List<WebAd> qyjkf = webAdService.findAdByCloName("企业级开发");
		List<WebAd> ydyy = webAdService.findAdByCloName("移动应用");
		List<WebAd> qpyx = webAdService.findAdByCloName("棋牌游戏");
		List<WebAd> avyy = webAdService.findAdByCloName("AR/VR应用");

		WebUtil.setRequestAttribute("qyjkf", qyjkf);
		WebUtil.setRequestAttribute("ydyy", ydyy);
		WebUtil.setRequestAttribute("qpyx", qpyx);
		WebUtil.setRequestAttribute("avyy", avyy);

		List<WebAd> allAd = new ArrayList<>();
		allAd.addAll(qyjkf);
		allAd.addAll(ydyy);
		allAd.addAll(qpyx);
		allAd.addAll(avyy);
		WebUtil.setRequestAttribute("allAd", allAd);

		return "/visitor/product-case";
	}

	@RequestMapping(value = "visitor/service")
	public String service() {

		WebAd hy = webAdService.findAdByCloNameOne("服务-行业解决方案");
		WebAd hlw = webAdService.findAdByCloNameOne("服务-移动互联网解决方案");
		WebAd ar = webAdService.findAdByCloNameOne("服务-AR增强现实");
		WebAd yx = webAdService.findAdByCloNameOne("服务-游戏开发");

		WebUtil.setRequestAttribute("hy", hy);
		WebUtil.setRequestAttribute("hlw", hlw);
		WebUtil.setRequestAttribute("ar", ar);
		WebUtil.setRequestAttribute("yx", yx);

		return "/visitor/service";
	}

	@RequestMapping(value = "visitor/recruitment")
	public String recruitment() {
		List<WebArticle> arts = artService.findByTypeName("人才招聘");
		WebUtil.setRequestAttribute("arts", arts);
		return "/visitor/recruitment";
	}

	/**
	 * 列表显示
	 */
	@RequestMapping(value = "visitor/findNews")
	public @ResponseBody AjaxResult showList(WebArticle webArticle, PaginationVO pageVo) {

		WebArticleType type = new WebArticleType();
		type.setArtTypeName("企业新闻");
		List<WebArticleType> types = artTypeService.findByModel(type);
		if (types.size() > 0) {
			webArticle.setArtTypeId(types.get(0).getArtTypeId());
		}
		return showList(artService, webArticle, pageVo);
	}

	@RequestMapping(value = "visitor/news")
	public String news() {
		return "/visitor/news";
	}

	@RequestMapping(value = "visitor/article")
	public String article(Long id) {
		WebUtil.setRequestAttribute("art", artService.findById(id));
		;
		return "/visitor/article";
	}

	@RequestMapping(value = "visitor/aboutus")
	public String aboutus() {

		WebArticle article = new WebArticle();
		article.setArtTitle("系统文章-关于我们");
		List<WebArticle> arts = artService.findByModel(article);
		if (arts.size() > 0) {
			article = arts.get(0);
		}
		WebUtil.setRequestAttribute("art", article);
		return "/visitor/about-us";
	}

	/**
	 * 返回百度统计内容
	 * 
	 * @return
	 */
	@RequestMapping(value = "baidu-verify-43DE60B411.txt")
	public String bdtj() {
		return "/visitor/baidutongji";
	}

}